/**
 * 计划列表
 */

$(function(){
	
	
	//提示信息初始设置
	toastr.options = {
			  "closeButton": true,
			  "debug": false,
			  "positionClass": "toast-top-center",
			  "onclick": null,
			  "showDuration": "1000",
			  "hideDuration": "1000",
			  "timeOut": "5000",
			  "extendedTimeOut": "1000",
			  "showEasing": "swing",
			  "hideEasing": "linear",
			  "showMethod": "fadeIn",
			  "hideMethod": "fadeOut"
			};
	
	showDateTable();
});


function showDateTable(a,b,c,d) {
	if (!jQuery().dataTable) {
		return;
	}
	dataTable=$('#sample_1').dataTable({
		"sDom" : "<'row'<'col-md-6 col-sm-12'l><'col-md-12 col-sm-12'f>r>t<'row'<'col-md-5 col-sm-12'i><'col-md-7 col-sm-12'p>>", //default layout without horizontal scroll(remove this setting to enable horizontal scroll for the table)
		"sAjaxSource":"web/loadPlanList.htm",
		"fnServerData": function ( sSource, aoData, fnCallback ) {
			if(a){aoData.push({name:"employeeName",value:a});}
			if(b){aoData.push({name:"departmentName",value:b});}
			if(c){aoData.push({name:"adress",value:c});}
			if(d){aoData.push({name:"phone",value:d});}
			if(a||b||c||d){//修改初始start
				for(var i=0;i<aoData.length;i++){
					if(aoData[i].name=="iDisplayStart"){
						aoData[i].value = 0;
					}
				}
			}
			$.ajax({
				"dataType":'json',
				"type": "POST",
				"url": sSource,
				"data": aoData,
				"success": fnCallback
			});
		},
		//"bDeferRender":true,
		"bFilter":false,
		"bLengthChange":false,//取消显示每页条数
		"bProcessing": true,
		"bServerSide": true,//true依据后台排序
		"bStateSave": true,
		"bJQueryUI":false,//是否用jquery样式
		"sZeroRecords": "没有检索到数据",
		/*"aoColumns": [
		              { 'mDataProp':'num',"bSortable": false,"sClass": "center","sTitle":"日期",
		            	  "mRender": function ( data, type, row ) {
		            		  return covertDateTime(data);
		            	  }
		              },
		              { 'mDataProp':'msgTitle',"bSortable": false,"sClass": "center","sTitle":"产品名称",
		            	  "mRender": function ( data, type, row ) {
		            		  if(data==null){
		            			  return " ";
		            		  }else{
		            			  if(data.length>15){
		            				  return '<span title='+data+'>'+data.substring(0,15)+'...</span>';
		            			  }else {
		            				  return data;
		            			  }		            			  
		            		  }
		            	  }
		              },
		              { 'mDataProp':'msgContent',"bSortable": false,"sClass":"center" ,"sTitle":"规格"},
		              { 'mDataProp':'msgType',"bSortable": false ,"sClass": "center","sTitle":"数量"},
		              { 'mDataProp':'msgDriverType',"bSortable": false,"sClass": "center","sTitle":"单位"},
		              { 'mDataProp':'msgUserType',"bSortable": false ,"sClass": "center","sTitle":"销售单价"},
		              { 'mDataProp':'createDate',"bSortable": false,"sClass": "center","sTitle":"合计"},
		              { 'mDataProp':'num',"bSortable": false,"sClass": "center","sTitle":"客户名称"},
		              { 'mDataProp':'num',"bSortable": false,"sClass": "center","sTitle":"部门"},
		              { 'mDataProp':'num',"bSortable": false,"sClass": "center","sTitle":"使用人"},
		              { 'mDataProp':'num',"bSortable": false,"sClass": "center","sTitle":"联系电话"},
		              { 'mDataProp':'num',"bSortable": false,"sClass": "center","sTitle":"进价"},
		              { 'mDataProp':'num',"bSortable": false,"sClass": "center","sTitle":"进价合计"},
		              { 'mDataProp':'num',"bSortable": false,"sClass": "center","sTitle":"计划状态"},
		              { 'mDataProp':'num',"bSortable": false,"sClass": "center","sTitle":"采购员"},
		              { 'mDataProp':'num',"bSortable": false,"sClass": "center","sTitle":"付款备注"},
		              { 'mDataProp':'num',"bSortable": false,"sClass": "center","sTitle":"操作",
		            	  "mRender": function ( data, type, row ) {
		            		return '<span><a href="javascript:void(0);">更改</a></span><span><a href="javascript:void(0);">删除</a></span>';
		            	  }
		              }
		              ],*/
          "aLengthMenu": [
                          [5, 10, 15, 20,50,100, -1],
                          [5, 10, 15, 20,50,100, "全部"] // change per page values here
                          ],
          "fnCreatedRow": function( nRow, aData, iDisplayIndex ) {
              $(nRow).on('click', function (){//行click击事件
              	if($(this).hasClass("active")){
              		$(this).removeClass("active")
              	}else{
              		$('#sample_1 tbody tr').removeClass("active");
              		var set = jQuery(this).attr("data-set");
              		$(this).toggleClass("active");
              		jQuery.uniform.update(set);
              	}
              });   
          },
          "bRetrieve": true, 
          "iDisplayLength": 15,
          "sPaginationType": "bootstrap",
          "oLanguage": {
        	  "sProcessing": '<i class="fa fa-coffee"></i>&nbsp;正在加载中......',
        	  "sEmptyTable" : "没有查询到数据",
        	  "sLengthMenu": "每页展示    _MENU_  条 ",
        	  "sInfo": "当前显示 _START_ 到 _END_ 条，共 _TOTAL_ 条记录",
        	  "oPaginate": {
        		  "sFirst": "首页",
        		  "sPrevious": "上一页 ",
        		  "sNext": "下一页",
        		  "sLast": "末页",
        	  }
          },
          "fnInitComplete": function() {
              this.fnAdjustColumnSizing(true);
           }

	});

	jQuery('#sample_1 .group-checkable').change(function () {
		var set = jQuery(this).attr("data-set");
		var checked = jQuery(this).is(":checked");
		jQuery(set).each(function () {
			if (checked) {
				$(this).attr("checked", true);
			} else {
				$(this).attr("checked", false);
			}
			$(this).parents('tr').toggleClass("active");
		});
		jQuery.uniform.update(set);

	});

	jQuery('#sample_1 tbody tr .checkboxes').change(function(){
		$(this).parents('tr').toggleClass("active");
	});

	jQuery('#sample_1_wrapper .dataTables_filter input').addClass("form-control input-medium"); // modify table search input
	jQuery('#sample_1_wrapper .dataTables_length select').addClass("form-control input-xbig"); // modify table per page dropdown
	jQuery('#sample_1 .dataTables_length select').select2(); // initialize select2 dropdown
	jQuery('#sample_1_processing').css("text-align","center");

}
